package company.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import company.common.R;
import company.domain.Forumposts;
import company.domain.Straypets;
import company.service.ForumpostsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class ForumpostsController {
    @Autowired
    ForumpostsService forumpostsService;
    /*
     * 连表查询
     * */
    @RequestMapping("/selectforumposts/{page}")
    public R selectForumposts(@PathVariable("page") int page){
        PageHelper.startPage(page,3);
        List<Map> list = forumpostsService.selectForumposts();
        PageInfo<Object> pageInfo = new PageInfo<>(list);
        return new R().add("pageInfo",pageInfo);
    }
    /*
     * 新增评论
     * */
    @PostMapping("/Addforumposts")
    public R AddForumposts(@RequestBody Forumposts forumposts){
        boolean save = this.forumpostsService.save(forumposts);
        if (save){
            new R().setCode(502);
        }
        return new R();
    }
}
